<div class="layui-card">
    <div class="layui-card-header">
        <h2 class="header-title">慢查询日志</h2>
        <span class="layui-breadcrumb pull-right">
          <a href="#!console">首页</a>
          <a><cite>慢查询日志</cite></a>
        </span>
    </div>
    <div class="layui-card-body">
        <div class="layui-form toolbar">
            搜索：
            <select id="sql-search-key">
                <option value="">-请选择-</option>
                <option value="query_str">查询语句</option>
            </select>&emsp;
            <input id="sql-search-value" class="layui-input search-input" type="text" placeholder="输入关键字"/>&emsp;
            <button id="sql-btn-search" class="layui-btn icon-btn"><i class="layui-icon">&#xe615;</i>搜索</button>
        </div>

        <table class="layui-table" id="slowQueryLog-table" lay-filter="slowQueryLog-table"></table>
    </div>
</div>
<script>
    layui.use(['form', 'table', 'util', 'config', 'admin'], function () {
        var table = layui.table;
        var config = layui.config;
        var util = layui.util;

        // 渲染表格
        table.render({
            elem: '#slowQueryLog-table',
            url: config.base_server + 'api-log/slowQueryLog?data='+new Date().getTime() ,
            method: 'GET',
            where: {
                access_token: config.getToken().access_token
            },
            page: true,
            cols: [[
                {type: 'numbers'},
                {
                    field: 'timestamp', width: 200, sort: true, templet: function (d) {
                        return util.toDateString(d.timestamp, 'yyyy-MM-dd HH:mm:ss');
                    }, title: '日志时间'
                },
                {field: 'query', sort: true, title: '查询语句'},
                {field: 'query_time', sort: true, title: '查询时间(ms)', width: 120},
                {field: 'lock_time', sort: true, title: '锁等待时间(ms)', width: 140},
                {field: 'rows_sent', sort: true, title: '返回行数', width: 110},
                {field: 'rows_examined', sort: true, title: '优化器扫描行数', width: 140}
            ]]
        });

        // 搜索按钮点击事件
        $('#sql-btn-search').click(function () {
            var key = $('#sql-search-key').val();
            var value = $('#sql-search-value').val();
            table.reload('slowQueryLog-table', {where: {searchKey: key, searchValue: value}});
        });
    });
</script>